import { Body, Controller, Delete, Get, Query } from '@nestjs/common';
import { MinioService } from './minio.service';

@Controller('minio')
export class MinioController {
  constructor(private readonly minioService: MinioService) {}

  @Get('server-address')
  getServerAddress() {
    return process.env.MINIO_SERVER;
  }

  @Get('bucket-list')
  async getBucketList() {
    return await this.minioService.getBuckets();
  }

  @Get('upload-url')
  async getUploadUrl(@Query('fileName') fileName: string) {
    return await this.minioService.presignedPutUrl(fileName);
  }

  @Get('download-url')
  async getDownloadUrl(@Query('fileName') fileName: string) {
    return await this.minioService.presignedGetUrl(fileName);
  }

  @Get('upload-url-post')
  async getUploadUrlPost(@Query('fileName') fileName: string) {
    return await this.minioService.presignedPostPolicy(fileName);
  }

  @Delete('batch-delete-file')
  async batchDeleteFile(@Body('fileNames') fileNames: string[]) {
    return await this.minioService.deleteFiles(fileNames);
  }
}
